// General_doubleLink.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "General_doubleLink.h"

void printList(void *ctx,DoubleElementT x)
{
	printf("%d",x);
}


int compare_int(void *pvData1,void *pvData2)
{
	return((int)pvData1 - (int)pvData2);
}


void sum_int(void *pvResult,void *pvData)
{
	*(int*)pvResult = (int)pvData + *(int *)pvResult;
}


int main(int argc, char* argv[])
{
	int i;
	int result = 0;
	PLIST pList= listCreate(NULL);
	POSITION pos = listEndGet(pList);
	for (i = 0; i < 8; i++)
	{
		listNodeInsert(pList,pos,(DoubleElementT)i);
		pos = listEndGet(pList);
	}
	printf("original data:\n");
	listTravese(pList,printList,&result);   /*print all data	 */
	printf("\n");
	pos = listDataFind(pList,(DoubleElementT)5,compare_int);
	listNodeDele(pList,pos);      
	printf("done data:\n");
	listTravese(pList,printList,&result);   /*printf data after deleted element 5	 */
	printf("\n");

	listTravese(pList,sum_int,&result);
	printf("the sum of all data : %d\n",result);
	listFree(pList);
	return 0;
}
